package com.yd.app.mapper;

import com.yd.app.mapper.provider.GTypeProvider;
import com.yd.domain.business.GType;
import com.yd.domain.business.Old;
import com.yd.domain.searchParam.GTypeParam;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author zy
 * @create 2018-03-08 17:15
 * @desc 商品类型
 **/
@Repository
public interface GTypemapper {
    /**
     * @Author: zy
     * @Desc: 录入商品类型
     * @Date:  2018/3/8
     * @Param
     */
    @Insert("INSERT INTO business_gType (id,typeName,price,ifUse,goodKind )" +
            " VALUES(#{o.id},#{o.typeName},#{o.price},#{o.ifUse},#{o.goodKind})")
    void addGType(@Param("o")GType o);

    /**
     * @Author: zy
     * @Desc: 修改数据
     * @Date:  2018/3/8
     * @Param
     */
    @Update("update business_gType set typeName=#{o.typeName},price=#{o.price},ifUse=#{o.ifUse},goodKind=#{o.goodKind} where id=#{o.id} ")
    void updateGType(@Param("o")GType o);
    /**
     * @Author: zy
     * @Desc: 删除数据
     * @Date:  2018/3/8
     * @Param
     */
    @Delete("delete from business_gType where id=#{id}")
    void deleteGType(@Param("id") String id);
    /**
     * @Author: zy
     * @Desc: 分页查询数据
     * @Date:  2018/3/8
     * @Param
     */
    @SelectProvider(method = "searchGTypeList",type= GTypeProvider.class)
    List<GType> searchGTypeList(@Param("gTypeParam") GTypeParam gTypeParam, @Param("startRow") int startRow, @Param("pageSize") int pageSize);
    /**
     * @Author: zy
     * @Desc:查询数量
     * @Date:  2018/3/7
     */
    @SelectProvider(method = "searchGTypeCount",type= GTypeProvider.class)
    int searchGTypeCount(@Param("gTypeParam") GTypeParam gTypeParam);
    /**
     * @Author: zy
     * @Desc: 修改状态：停用
     * @Date:  2018/3/8
     * @Param
     */
    @Update("update business_gType set ifUse=#{o.ifUse} where id=#{o.id} ")
    void updateIfUse(@Param("o")GType o);
    /**
     * @Author: zy
     * @Desc: 批量停用、或者是启用
     * @Date:  2018/3/9
     * @Param
     */
    @SelectProvider(method = "updateAllIfUse",type=GTypeProvider.class)
    void updateAllIfUse(@Param("gType")GType gType);
    /**
     * @Author: zy
     * @Desc: 批量删除
     * @Date:  2018/3/9
     * @Param
     */
    @SelectProvider(method = "deleteAll",type=GTypeProvider.class)
    void deleteAll(@Param("gType")GType gType);
    /**
     * @Author: zy
     * @Desc: 获取商品类型
     * @Date:  2018/4/12
     * @Param
     */
    @Select("select * from business_gType where ifUse=1 ")
    List<GType> getGoodType(@Param("goodKind")String goodKind);

    /**
     * @Author: sxh
     * @Desc: 获取商品类型列表
     * @Date:  2018/4/12
     * @Param
     */
    @Select("select * from business_gType where ifUse=1 ")
    List<GType> getGTypeList(@Param("type")String type);

    /**
     * 一键更新该类型 所有商品价格
     * @param type
     * @param price
     */
    @Update(" update business_goods set price=#{price} where type=#{type} and typeOne=#{pId} ")
    void updateAllGoodsPriceByGtype(@Param("pId")String pId,@Param("type") String type,@Param("price") float price);

    @Select("select * from business_gType where id in (${ids}) ")
    List<GType> getListByIds(@Param("ids") String ids);
}
